package com.yh.tea.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yh.tea.entity.GoodsManage;
import com.yh.tea.service.GoodsManageService;
import com.yh.tea.utiity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yh
 * @since 2024-03-18
 */
@RestController
@RequestMapping("/goods-manage")
public class GoodsManageController {
    @Autowired
    private GoodsManageService goodsManageService;

    //上架商品
    @PostMapping("/add")
    public ResponseResult add(@RequestBody GoodsManage goodsManage){
        Boolean result=goodsManageService.save(goodsManage);
        return ResponseResult.success(result?"上架成功":"上架失败",result);
    }
    //下架商品
    @PostMapping("/del")
    public ResponseResult del(@RequestBody List<Long> ids) {
        Boolean result=goodsManageService.removeBatchByIds(ids);
        return ResponseResult.success(result?"下架成功":"下架失败");
    }
    //修改商品信息
    @PostMapping("/update")
    public ResponseResult update(@RequestBody GoodsManage goodsManage){
        Boolean result=goodsManageService.update(goodsManage,new QueryWrapper<GoodsManage>().eq("id",goodsManage.getGoodsId()));
        return ResponseResult.success(result?"修改成功":"修改失败");
    }
    //获取分页数据
    @PostMapping("/getPage")
    public ResponseResult getPage(){
        return goodsManageService.getPage();
    }

}

